<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
//	$data['jses'] = array('js/manager/acl.js');
	$data['csses'] = array('css/acl.css');
	$this->load->view('/manager/inc/header',$data);
?>
</head>
<body>
<?php
	$this->load->view('manager/inc/nav');
?>
<?php if(isset($message) && $message){?>
<div class="tips_v2"><span class="boldred">错误提示：</span><span><?php echo $message;?></span></div>
<?php }?>
<div class="current_main_v2">
<div class="list-tab">
	<ul>
		<li <?php if($action == 'list') echo 'class="cur"'?>><a href="<?php echo site_url('manager/acl/role');?>">角色列表</a></li>
		<li <?php if($action == 'add') echo 'class="cur"'?> title="新增角色"><a href="<?php echo site_url('manager/acl/role/operate');?>" title="新增角色">新增角色</a></li>
		<?php if($action == 'edit') 
			echo '<li class="cur" title="编辑角色">编辑角色</li>';
		?>
	</ul>
</div>
<?php if($action == 'list'){?>
<table class="list-table list-table-s">
	<thead>
		<tr>
			<th align="left" width="100">角色名称</th>
			<th align="left" width="100">操作</th>
			<th align="left" width="100">角色名称</th>
			<th align="left" width="100">操作</th>
			<th align="left" width="100">角色名称</th>
			<th align="left" width="100">操作</th>
		</tr>
	</thead>
	<tbody>
	<?php
		if(isset($list) && count($list)){
			$i = 0;
	?>
		<tr>
		<?php 
			foreach ($list as $item) {
				if($i != 0 && $i % 3 == 0){
		?>
		</tr><tr>
		<?php }$i++;?>
			<td align="left" width="100"><?php echo $item['name'];?></td>
			<td align="left" width="100">
				<a href="<?php echo site_url('manager/acl/role/operate/'),'/',$item['rid'];?>">编辑</a>
				<?php if($item['num'] == 0){?>
				/ <a href="<?php echo site_url('manager/acl/role/dodelete/'),'/',$item['rid'];?>">删除</a>
				<?php }?>
			</td>
	<?php }}else{?>	
			<td colspan="6" align="center">	
				对不起，暂无数据！
			</td>
	<?php }?>
		</tr>
	</tbody>
</table>
<?php }else if($action == 'add' || $action == 'edit'){

?>
<script>
	$(function($){
		new plugor.form({id:'acl_role',type:'ajax'});
	});
	function checkAll(self,parentid,childname){
		$('#'+parentid).find('input[name^='+childname+']').attr('checked', $(self).attr('checked'));
	}
</script>
<form id="acl_role" action="<?php echo site_url('manager/acl/role/dooperate');?>" method="post">
	<table class="list-table list-table-s form5">
		<thead>
			<tr>
				<th colspan="2" align="left" height="35">
					<div style="float:left;line-height:27px;"><span class="red">* </span>名称：</div>
					<?php if($action == 'edit'){?>
						<input type="hidden" name="role[rid]" value="<?php if(isset($role)) echo $role['rid']?>" />
					<?php }?>
					<input valid="required|alpha_chinese|is_exist:<?php if(isset($role)) echo $role['name'].'@';echo site_url('manager/acl/role/isExistName')?>" id="role_name" name="role[name]" type="text" value="<?php if(isset($role)) echo $role['name']?>"/>
					<div id="role_name_tip"></div>
				</th>
			</tr>
			<tr>
				<th colspan="2" align="left" height="35">
					<div style="float:left;line-height:27px;">&nbsp;&nbsp; 排序：</div>
					<input valid="integer" name="role[sort]" type="text" value="<?php if(isset($role)) echo $role['sort']?>"/>
				</th>
			</tr>
			<tr>
				<th colspan="2" align="left"><label><input type="checkbox" onclick="checkAll(this,'pids','pid');"/>全选</label></th>
			</tr>
		</thead>
		<tbody id="pids">
		<?php 
			$first = true;
			$temp_mid = 0;
			$pids = ','.(isset($role)?$role['pids']:'').',';
			foreach ($permissions as $item) {
				$mid = $item['mid'];
				if($temp_mid != $mid){
					$temp_mid = $mid;
					if(!$first){
						echo '</ul></td></tr>';
					}else{
						$first = false;
					}
					echo '<tr><td align="left" width=150><label style="color:#369;"><input type="checkbox" name="pid_mid" onclick="checkAll(this,\'mid_',$item['mid'],'\',\'pid\');"/>',$item['mname'],'</label></td><td><ul class="acl_p_ul" id="mid_',$item['mid'],'">';
				}
				echo '<li><label><input type="checkbox" ',(substr_count($pids,','.$item['pid'].',')>0?'checked=true':''),' name="pid[]" value="',$item['pid'],'"/>',$item['pname'],'</label></li>';
			}
		?>
		</tbody>
		<tfoot>
			<tr>
				<th colspan="4" align="center" height="35">
					<input type="submit" value="提交"/>
				</th>
			</tr>
		</tfoot>
	</table>
</form>
<?php }?>
</div>
<?php $this->load->view('/member/inc/footer');?>
</body>
</html>